<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>页面控制台 - WingsJ</title>

  <style>
    html {
      font-size: 20px;
      font-family: 'Microsoft Jhenghei';
    }

    body {
      padding: 4rem;
    }
  </style>
  <script type="module">
    import Stats from './lib/stats.module.js';
    import { GUI } from './lib/dat.gui.module.js';

    window.Control = {}

    const AnimationArray = [ // 需要周期调用的函数添加到这个数组中
      () => {
        window.requestAnimationFrame(timestamp => {
          for (let el of AnimationArray) {
            el(timestamp)
          }
        })
      }
    ]
    window.Control.AnimationArray = AnimationArray

    const stats = new Stats()
    AnimationArray.push(() => {
      stats.update()
    })
    const gui = new GUI();
    window.Control.GUI = gui

    document.addEventListener('DOMContentLoaded', () => {
      document.body.appendChild(stats.dom)
      window.requestAnimationFrame(AnimationArray[0])
    })
  </script>

  <style>
    .div {
      width: 100px;
      height: 100px;
      margin-bottom: 2rem;
      background-color: skyblue;
      animation: move 3s alternate forwards;
      animation-iteration-count: infinite;
    }

    @keyframes move {
      from {
        transform: translateX(0);
        background-color: skyblue;
      }

      to {
        transform: translateX(500px);
        background-color: pink;
      }
    }

    @keyframes move-6 {
      from {
        transform: translateX(0);
        background-color: skyblue;
      }

      20% {
        transform: translateX(100px);
      }

      40% {
        transform: translateX(200px);
      }

      60% {
        transform: translateX(300px);
      }

      80% {
        transform: translateX(400px);
      }

      to {
        transform: translateX(500px);
        background-color: pink;
      }
    }

    #div-1 {
      animation-timing-function: ease;
    }

    #div-2 {
      animation-timing-function: ease-in;
    }

    #div-3 {
      animation-timing-function: ease-out;
    }

    #div-4 {
      animation-timing-function: ease-in-out;
    }

    #div-5 {
      animation-timing-function: linear;
    }

    #div-6 {
      animation-timing-function: step-start;
    }

    #div-7 {
      animation-timing-function: step-end;
    }

    #div-8 {
      animation-timing-function: cubic-bezier(1.00, 0.00, 0.00, 1.00);
    }

    #div-9 {
      animation-timing-function: steps(10, end);
    }
  </style>
</head>

<body>
  <div>#1-ease</div>
  <div id="div-1" class="div"></div>
  <div>#2-ease-in</div>
  <div id="div-2" class="div"></div>
  <div>#3-ease-out</div>
  <div id="div-3" class="div"></div>
  <div>#4-ease-in-out</div>
  <div id="div-4" class="div"></div>
  <div>#5-linear</div>
  <div id="div-5" class="div"></div>
  <div>#6-step-start</div>
  <div id="div-6" class="div"></div>
  <div>#7-step-end</div>
  <div id="div-7" class="div"></div>
  <div>#8-cubic-bezier</div>
  <div id="div-8" class="div"></div>
  <div>#9-steps</div>
  <div id="div-9" class="div"></div>

  <script type="module">
    let param = {
      infinite: true,
      multiStep: false
    }
    Control.GUI.add(param, 'infinite').onChange(ev => {
      let style = document.styleSheets[1].cssRules[0].style

      if (ev) {
        style.animationIterationCount = 'infinite'
      } else {
        style.animationIterationCount = 1
      }
    })
    Control.GUI.add(param, 'multiStep').onChange(ev => {
      let style = document.styleSheets[1].cssRules[0].style

      if (ev) {
        style.animationName = 'move-6'
      } else {
        style.animationName = 'move'
      }
    })

  </script>
</body>

</html>